package cn.tedu.charging.cost.dao.repository;

import cn.tedu.charging.common.pojo.po.ChargingCostRulePO;
import cn.tedu.charging.cost.dao.mapper.ChargingCostRuleMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CostRepository {
    @Autowired
    private ChargingCostRuleMapper chargingCostRuleMapper;

    public ChargingCostRulePO getCostRule(Integer stationId, Integer hour) {
        //where station_id=? and start_time<=#{hour} and end_time>#{hour}
        QueryWrapper<ChargingCostRulePO> queryWrapper=new QueryWrapper<>();
        //业务中 定义时间段[0,8) [8,12) [12,14) [14,18) [18,24)
        //eq=equal lt=less than lte=less than and equal gt gte=greater than and equal
        queryWrapper.eq("station_id",stationId);
        queryWrapper.le("start_time",hour);
        queryWrapper.gt("end_time",hour);
        return chargingCostRuleMapper.selectOne(queryWrapper);
    }
}
